﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Managers;
using RRRSRoguelikeData;

namespace RRRSRoguelike.Entities
{
    /// <summary>
    /// Player inherits from creature.
    /// </summary>
    public class Player : Creature
    {

        #region variables
        private DungeonManager dungeonManager = DungeonManager.Instance;
        private Weapon weaponSlot;
        public event EventHandler WeaponChanged;
        public Stats Stats;
        #endregion

        #region constructor
        /// <summary>
        /// Initializes player
        /// </summary>
        /// <param name="p"></param>
        public Player(Point position,TileData tileData)
            : base(position,tileData)
        {
        }
        #endregion

        #region properties
        public void AddWeapon(Weapon weapon) 
        {
        	weaponSlot = weapon;
        	if(WeaponChanged!=null)
        	WeaponChanged(this,null);        	 
        }
        
        public void RemoveWeapon()
        {
        	weaponSlot = null;
        	if(WeaponChanged!=null)
        	WeaponChanged(this,null);
        }
        
        public bool HasWeapon()
        {
        	return weaponSlot !=null;
        }
        
        public void UseWeapon()
        {
        	weaponSlot.Use(this);
        }
        
        public Weapon WeaponSlot
        {
        	get{ return weaponSlot; }
        }
        	
        #endregion

        #region methods
        // This should be two separate methods.  Add one to the tile.
        public Boolean MovePlayer(Direction direction,int distance = 1)
        {
            //check for valid move
            for (int i = distance; i > 0; i--)
            {
                Point newPosition = DungeonLevel.GetNewPosition(Position,direction, i);
                if (dungeonManager.DungeonLevel.IsOKToMove(newPosition))
                {
                    Position = newPosition;
                    return true;
                }
            }
            return false;
        }


        #endregion

    }
}
